/**
 * https://leetcode.cn/problems/top-k-frequent-elements/submissions/550101155/
 * 347.前k个高频元素
 * medium 2024.07.27
 * 优先队列
 */

class Solution {
public:
    typedef pair<int,int> P;
    static bool cmp(const P& a,const P& b){
        return a.second>b.second;
    }
    vector<int> topKFrequent(vector<int>& nums, int k) {
        map<int,int> mp;
        for(auto num:nums)
        mp[num]++;
        vector<P> vp(mp.begin(),mp.end());
        sort(vp.begin(),vp.end(),cmp);
        vector<int> v;
        for(int i=0;i<k;++i)
        v.push_back(vp[i].first);
        return v;
    }
};